import {
  makeAutoObservable,
  // makeObservable,
  // action,
  // observable
  runInAction
} from "mobx";
import { myFectch } from '../../utils/useFetch'
class Order {
  constructor() {
    makeAutoObservable(this, {}, { autoBind: true })
  }
  count = []
  myData = [];
  get tashop() {
    return this.myData.map((v,index) => {
       if(v){
        v.key = index
       }
       return v
    })
  }
  //显示商品类目信息
  async commodity() {
    const commodity = await myFectch({
     url: 'http://42.192.83.237:8080/portal/goodsCategory/showGoodsCategory?page=1&limit=100', method: 'GET',
     headers: "application/x-www-form-urlencoded"
   })
   runInAction(()=>{
    if(commodity.data){
    this.myData=commodity.data
    // console.log(this.myData);
   }else{
    this.myData=[]
   }
   })
  }
  //修改类目信息
  async compileData(key, miChen, quZhong){
    const date = await myFectch({
      url: 'http://42.192.83.237:8080/portal/goodsCategory/saveOrUpdateGoodsCategory', method: 'POST', data: {
        id:key,
        weight:quZhong,
        categoryName:miChen
      },
      // headers: "application/x-www-form-urlencoded"
    })
    runInAction(()=>{
      this.commodity()
    })
    console.log(date);
  }
  // 添加
  async compileAdd(key,miChen, quZhong){
    const todate = await myFectch({
      url: 'http://42.192.83.237:8080/portal/goodsCategory/saveOrUpdateGoodsCategory', method: 'POST', data: {
        id:key,
        weight:quZhong,
        categoryName:miChen
      },
      // headers: "application/x-www-form-urlencoded"
    })
    runInAction(()=>{
      this.commodity()
    })
    console.log(todate);
  }
  get tableData() {
    return this.count.map((v,index) => {
       if(v){
        v.key = index
       }
       return v
    })
  }
  //分页查询所有的订单信息
  async trackOrder() {
     const date = await myFectch({
      url: 'http://42.192.83.237:8080/admin/orderVo/selectAllOrderVoByPage', method: 'POST', data: {
        page: 1,
        limit: 1000
      },
      headers: "application/x-www-form-urlencoded"
    })
    runInAction(()=>{
      this.count = date.data.map((el, index) => {
      el.orderStatus = el.orderStatus === '1' ? '正常' : '冻结'
      el.key = index
      return el
    })
    })

  }
  //根据id查询总订单信息
  async ById(coid) {
    if(coid==='') return this.trackOrder()
    const textId = await myFectch({ 
      url: 'http://42.192.83.237:8080//admin/orderVo/selectOrderVoById', method: 'POST', data: {
        id: coid,
      },
      headers: "application/x-www-form-urlencoded"
    })
    if(textId.data){
      this.count = [textId.data].map((el,index) => {
        el.orderStatus = el.orderStatus === '1' ? '正常' : '冻结'
        el.key=index
        return el
      })
      runInAction(()=>{
        this.count=[textId.data]
      })
    } else{
      alert('没得')
      this.count=[]
    }
  }
  //分页查询所有的订单信息
  async mushNum(shopName,ophoneNum,orderT,orderStatus,allusiness,money,toDay) {
    const mushNum = await myFectch({ 
      url: 'http://42.192.83.237:8080//admin/orderVo/selectOrderVoById', method: 'POST', data: {
        page:1,
        limit:1000,
        goodsName:shopName,
        memberPhone:ophoneNum,
        orderStatus:orderStatus,
        franchisee:allusiness,
        orderAmount:money,
        orderTime:toDay,
      },
      headers: "application/x-www-form-urlencoded"
    })
    if(mushNum.data==null){
      alert('暂无数据')
    }else{
      runInAction(()=>{
        this.count=mushNum
      })
    }
    // console.log(mushNum)
}
}
const order = new Order()
export default order